{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tkinter: Buttons"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Button is another standard widget in python tkinter lib\n",
    "- With button you can interact with program \n",
    "- In Label text and be display in diffrent font but in button single only\n",
    "- In button you can use text as well as Image"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Noraml Button"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from tkinter import *\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "root = Tk()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def start_button():\n",
    "    print(\"Start Button Work\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def stop_button():\n",
    "    print(\"Stop Button Wrok\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "button_start = Button(root,\n",
    "                      text=\"start\",\n",
    "                      width=15,\n",
    "                      command=start_button)\n",
    "\n",
    "button_stop = Button(root,\n",
    "                     text=\"stop\",\n",
    "                     width=15,\n",
    "                     command=stop_button)\n",
    "\n",
    "button_start.pack()\n",
    "button_stop.pack()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Start Button Work\n",
      "Stop Button Wrok\n"
     ]
    }
   ],
   "source": [
    "root.mainloop()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Radio Button"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Radio Button, sometime called option button, which allow user to choose one of predefine set of options.\n",
    "- Radio button can contain text or images\n",
    "- The button can only display text in single font\n",
    "- A python fuction or method can be associated with radio button. That fuction or method will be called as you press this radio button"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from tkinter import *\n",
    "root = Tk()\n",
    "root.title(\"Radio Button\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Label(root,\n",
    "     text=\"Select True or False\",\n",
    "     justify=LEFT\n",
    "     ).pack()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Variables in Tkinter:\n",
    "    - StringVar() : Hold a string and default value is \"\"\n",
    "    - IntVar()    : Hold a integer and default value is 0\n",
    "    - DoubleVar() : Hold a float and default value is 0.0\n",
    "    - BooleanVar(): Hold a boolean and return True or False\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = BooleanVar()\n",
    "\n",
    "def data_print():\n",
    "    print(data.get())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "true_button = Radiobutton(root,\n",
    "                          text = \"Ture\",\n",
    "                          variable=data,\n",
    "                          value= True,\n",
    "                          padx=20,\n",
    "                          pady=5,\n",
    "                          command = data_print\n",
    "                          )\n",
    "\n",
    "false_button = Radiobutton(root,\n",
    "                           text = \"False\",\n",
    "                           variable=data,\n",
    "                           value= False,\n",
    "                           padx=20,\n",
    "                           pady=5,\n",
    "                           command = data_print\n",
    "                          )\n",
    "true_button.pack()\n",
    "false_button.pack()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "root.mainloop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
